package fag.core.game.test.arkanoid;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import fag.core.geometry.Rectangle2D;
import fag.core.geometry.Vector2D;
import fag.core.model.Animation;
import fag.core.model.Frame;
import fag.core.model.Model;
import fag.core.model.SerializableImage;
import fag.core.model.Sprite;

public class RacketModel extends Model {

	private static final long serialVersionUID = 3374004212823486767L;

	public RacketModel() {
		
		loadRacketModel("small");
		loadRacketModel("normal");
		loadRacketModel("large");
		loadRacketModel("mini");
		loadRacketModel("gun");
		
		loadDestroyModel();
	}
	
	private void loadDestroyModel() {
		Animation a = new Animation("destroy");
		Frame f1 = new Frame(200);
		Frame f2 = new Frame(200);
		Frame f3 = new Frame(200);
		BufferedImage b1 = null;
		BufferedImage b2 = null;
		BufferedImage b3 = null;
		try {
			b1 = ImageIO.read(getClass().getResourceAsStream("/imgs/arkanoid/rackets/destroy1.png"));
			b2 = ImageIO.read(new File(System.getProperty("user.dir")+"/src/imgs/arkanoid/rackets/destroy2.png"));
			b3 = ImageIO.read(new File(System.getProperty("user.dir")+"/src/imgs/arkanoid/rackets/destroy3.png"));
		} catch (IOException e) {
			e.printStackTrace();
		}
		Sprite s1 = new Sprite(new SerializableImage(b1),new Vector2D());
		Sprite s2 = new Sprite(new SerializableImage(b2),new Vector2D());
		Sprite s3 = new Sprite(new SerializableImage(b3),new Vector2D());
		Rectangle2D hitbox1 = new Rectangle2D(0, 0, s1.getWidth(), s1.getHeight());
		Rectangle2D hitbox2 = new Rectangle2D(0, 0, s2.getWidth(), s2.getHeight());
		Rectangle2D hitbox3 = new Rectangle2D(0, 0, s3.getWidth(), s3.getHeight());
		f1.setHitbox(hitbox1);
		f1.setSprite(s1);
		f1.updateBounds();
		f2.setHitbox(hitbox2);
		f2.setSprite(s2);
		f2.updateBounds();
		f3.setHitbox(hitbox3);
		f3.setSprite(s3);
		f3.updateBounds();
		a.addFrame(f1);
		a.addFrame(f2);
		a.addFrame(f3);
		getListAnimation().add(a);
	}
	
	private void loadRacketModel(String name) {
		
		Animation a = new Animation(name);
		Frame f1 = new Frame(200);
		BufferedImage bufferedImage = null;
		try {
			bufferedImage = ImageIO.read(new File(System.getProperty("user.dir")+"/src/imgs/arkanoid/rackets/" + name + ".png"));
		} catch (IOException e) {
			e.printStackTrace();
		}
		Sprite s1 = new Sprite(new SerializableImage(bufferedImage),new Vector2D());
		Rectangle2D hitbox1 = new Rectangle2D(0, 0, s1.getWidth(), s1.getHeight());
		f1.setHitbox(hitbox1);
		f1.setSprite(s1);
		f1.updateBounds();
		a.addFrame(f1);
		getListAnimation().add(a);
	}
}
